#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <assert.h>
#include <sys/types.h>
#include <sys/wait.h>
int main(int argc, char*argv[])
{
    printf("The process is running...\n");
    pid_t id = fork();
    assert(id!=-1);
    if(id==0)
    {
        //child process
        sleep(1);
        // ./myexec ls -a -l 
        execvp(argv[1],&argv[1]);

        exit(1);// 如果调用失败，直接让子进程退出
    }
    int status = 0;
    pid_t ret=waitpid(id,&status,0);
    if(ret == id)
    {
        printf("wait success, exit code:%d , signal number:%d\n",(status>>8)&0xFF,status&0x7F);
    }























    // .c --> .exe --> load into memory --> process --> running
   // printf("The process is running...\n");
   // 
   // execl("/usr/bin/lsafa","ls","-a","-l","--color=auto",NULL);// 传参以NULL结尾，来表示传参结束
   // 
   // perror("execl");

   // printf("The process finishes running...\n");

   // exit(1);
    return 0;
}
